// import { Marker } from '@antv/g-canvas/lib/shape';

export default function(G6) {
    G6.registerBehavior('hoverElementActived', {
        getEvents() {
            return {
                'node:mouseenter': 'onNodeEnter',
                'node:mouseleave': 'onNodeLeave',
                'anchor:mouseleave': 'onAnchorLeave',
                'edge:mouseover': 'onEdgeMouseOver',
                'edge:mouseleave': 'onEdgeMouseLeave',
            };
        },
        onAnchorLeave(e) {
            let node = e.item.getContainer().getParent();
            if (node && !this.graph.get('onDragEdge')) {
                this.graph.setItemState(node.get('item'), 'show-anchor', false);
                this.graph.setItemState(node.get('item'), 'hover', false);
                this.graph.setItemState(e.item, 'hover', false);
            }
        },
        onNodeEnter(e) {
            if (!this.graph.get('onDragEdge')) {
                this.graph.setItemState(e.item, 'show-anchor', true);
                this.graph.setItemState(e.item, 'hover', true);
            }
        },
        onNodeLeave(e) {
            if (!(e.target?.cfg?.type === 'marker') && !this.graph.get('onDragEdge')) {
                this.graph.setItemState(e.item, 'show-anchor', false);
                this.graph.setItemState(e.item, 'hover', false);
            }
        },
        onEdgeMouseOver(e) {
            if (!e.item.hasState('selected') && !e.item.hasState('running')) this.graph.setItemState(e.item, 'hover', true);
        },
        onEdgeMouseLeave(e) {
            if (!e.item.hasState('selected') && !e.item.hasState('running')) this.graph.setItemState(e.item, 'hover', false);
        },
    });
}
